<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <!-- nlogn -->
    <script>
        function shellSort(arr) {
          let len = arr.length;
          for(let gap = Math.floor(len / 2);gap>0;gap = Math.floor(gap/2)) {
            for(let i = gap;i < len;i++) {
              let j = i;
              let current = arr[i];
              while(j-gap >= 0 && current < arr[j-gap]) {
                arr[j] = arr[j-gap];
                j=j-gap;
              }
              arr[j] = current;
            }
          }
          return arr;
        }
        console.log(shellSort([1,2,3,5,9,8,7,4,1]));
    </script>
</body> 
</html>